package java19_4_25.com.huweilong.wait_notify;

import java.util.concurrent.TimeUnit;

public class Demo1 {
    static class MyThread extends Thread {
        private Object o;

        MyThread(Object o) {
            this.o = o;
        }

        @Override
        public void run() {
            try {
                System.out.println(125);
                TimeUnit.SECONDS.sleep(5);
                System.out.println(123);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            synchronized (o) {
                System.out.println("唤醒主线程");
                o.notify();
                System.out.println(126);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Object o = new Object();

        MyThread t = new MyThread(o);
        t.start();
        System.out.println(123);
        synchronized (o) {
            System.out.println(123);
            o.wait();
            System.out.println("永远不会到达");
        }
    }
}
